package com.example.mybatis20231226.Mapper;

import com.example.mybatis20231226.Model.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserInfoMapper {
    @Select("select * from userinfo")
    public List<UserInfo> selectAll();

    @Select("select * from userinfo where id=4")
    public UserInfo getById();

    @Select("select * from userinfo where id=#{id}")
    public UserInfo getById1(Integer id);

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into userinfo (username, `password`, age, gender, phone)" +
            "values (#{User.username}, #{User.password}, #{User.age}, #{User.gender}, #{User.phone})")
    public Integer insert(@Param("User") UserInfo userInfo);

    @Delete("delete from userinfo where id=#{id}")
    public void delete(Integer id);

    @Update("update userinfo set gender=#{gender} where id=#{id}")
    public void update(Integer gender, Integer id);

    @Select("select id, username, password, age, gender, delete_flag as deleteFlag," +
            "create_time as createTime, update_time as updateTime from userinfo")
    public List<UserInfo> selectAll1();

    @Results(id = "BaseMap", value = {
            @Result(column = "delete_flag", property = "deleteFlag"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "update_time", property = "updateTime")
    })
    @Select("select id, username, password, age, gender, delete_flag," +
            "create_time, update_time from userinfo")
    public List<UserInfo> selectAll2();

    @ResultMap("BaseMap")
    @Select("select id, username, password, age, gender, delete_flag," +
            "create_time, update_time from userinfo where id=#{id}")
    public UserInfo getById2(Integer id);

    @Select("select * from userinfo")
    public List<UserInfo> selectAll3();
}
